<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html  xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>聚合二维码管理-添加/编辑</title>
	<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
	<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
	<script src="js/json2.js" type="text/javascript"></script>
	<script type="text/javascript">

	var riskMainType = "";//全局的产品大类字段。新增时在配置第一个子二维码时赋值，编辑时由已配置二维码带出。
	var codeId = "";
	$(document).ready(function() {
			$("#scanCodebutton").attr("display","none");
			$("#scanCodeSaveButton").attr("display","");
	});
	
	
	function addNewUnionCode(){
		var unionCodeName = $.trim($('#unionScanQRCodeName').val());
		var unionCodeDesc = $.trim($('#unionScanQRCodeDesc').val());
		if(unionCodeName == null || unionCodeName.length == 0){
			$.message("error","请录入聚合二维码名称。")
			return ;
		}
		$.openLoading();
		$.ajax({
			url : "<%=path%>/unionScanConfig/addNewUnionCode",
			type : 'POST',
			async : true,
			data:{codeName:unionCodeName,codeDesc:unionCodeDesc},
			dataType:'json',
			success:function(rs){
				/!* $.closeLoading(); *!/
				if(!rs.result){
					$.message("fail","保存失败！请联系管理员");
				}else{
					var id = rs.data;
					$.message("success","新增保存成功，可以配置关联子二维码");
					setTimeout(function(){
						window.location.href="<%=path%>/unionScanConfig/edit?codeId="+id;
					},"1500")
				}
			}
		});
	}

	//---------------------------------------子二维码配置窗体相关方法 begin --------------------------------------
	//展示选择子菜单窗体
	function openScanCodeDiv(){
		if(type=='add'){
			
			$.message("warn","请先保存该聚合二维码后再配置子菜单");
			
			return;
		}
		
		$("#scanCodeDiv").OpenDiv();	
		// queryScanCode(1);
		queryScanMenu(1);
	}

	//拼接查询合作伙伴 字符串
	function queryScanMenu(pageIndex){
		//菜单id
		var menuId = $.trim($('#menuId').val());
		//菜单名称
		var menuName = $.trim($('#menuName').val());

		loadScanCode({current:pageIndex,size:8,menuId:menuId,menuName:menuName});
	}

	//查询待配置的二维码列表
	function loadScanCode(param){
		$.openLoading();
		$.ajax({
			url : "<%=path%>/unionScanConfig/queryScanMenu?"+new Date().getTime(),
			type : 'POST',
			async : true,
			data:param,
			dataType:'json',
			success:function(page){
				$.closeLoading();
				if($.validate(page)){
					return;
				}
				var checkboxObj ="<input class='input_fxk' name='checkboxScanCode' type='checkBox' value=''>";
				var fieldNames = "id@TDH,menu_name,menu_desc";
				var tableContent = creatTable1(fieldNames,page,checkboxObj);
				var tableObj = $("#scanCodeTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				var strPage = creatChannelPage2(param.current,6,page.maxPage,"108");
				var pageDIV = $("#scanCodePageDiv");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				$('#channelInfoDiv').OpenDiv();
				bindradio();
			}
		});
	}
	
	//拼接查询合作伙伴 字符串
	function queryScanCode(pageIndex){
		//规则id
		var ruleId = $.trim($('#ruleId').val());
		//代理人编码
		var agentId = $.trim($('#agentId').val());
		//方案号
		var planNo = $.trim($('#planNo').val());

		loadScanCode({current:pageIndex,size:8,ruleId:ruleId,agentId:agentId,planNo:planNo,riskMainType:riskMainType,unionCodeId:codeId});
	}
	
	//关闭选择子二维码窗体
	function closeScanCodeDiv(){
		$("#scanCodeDiv").CloseDiv();	
	}

	//---------------------------------------子二维码配置窗体相关方法 begin --------------------------------------
	
	//加载已配置的子菜单列表：
	function queryConfigedScanCode(pageIndex){
		loadConfigedScanCode(1);
	}
	
	function loadConfigedScanCode(pageIndex){
		var param = {current:pageIndex,size:8,menuId:codeId};
		$.ajax({
			url : "<%=path%>/unionScanConfig/queryConfigedMenu",
			type : 'POST',
			async : true,
			data:param,
			dataType:'json',
			success:function(page){
				$.closeLoading();
				if($.validate(page)){
					return;
				}
				var lastbutton = "<a href='javascript:void(0)' onClick='deleteConfigedUnionCode(this);return false'>删除</a>";
				var fieldNames = "ID@TDH,MENU_NAME,MENU_DESC";
				var tableContent = creatTable(fieldNames,page,lastbutton);
				var tableObj = $("#configedUnionQRCodeTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);			
				var strPage = creatChannelPage2(param.current,6,page.maxPage,"107");
				var pageDIV = $("#configedUnionQRCodeDiv");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
				bindradio();
			}
		});
	}
	
	//绑定单选按钮事件，选中某个单选按钮，该按钮所在行高亮显示
	function bindradio(){
		$("input[name='radioNlifePlan']").click(function(){
			$("input[name='radioNlifePlan']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
       	});
		$("input[name='radioChannelInfo']").click(function(){
			$("input[name='radioChannelInfo']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
       	});
	}

	</script>
</head>
<body >
	<div class="current">
           <table class="current_table_1">
              <tbody>
                <tr class="f2">
                  <td>
                    <img src="./images/current_1.jpg">
                  </td>
                  <td class="current_table_1_td">
                    <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                      <span style=" color:#136bab; ">界面出单管理
                      <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>聚合二维码管理
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody>
         </table>
      </div>
		
		<table class="table_02" id="table">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
						 	<td  style="width:'20%' height:'30';text-align: center;">
								二维码名称：<input id="unionScanQRCodeName" class="input_text">
								二维码描述：<input id="unionScanQRCodeDesc" type="text" class="input_text">
	                  	        <input type="button"  class="input_button_2" id="scanCodeSaveButton"  value="保存" onClick="addNewUnionCode()"/>&nbsp;&nbsp;
							</td>
						</tr>
						<tr height="30px">
						</tr> 
					</table>
				</td>
			</tr>

		</table>
	<!-- begin ------------------------ 配置子二维码 DIV 默认隐藏--------------------------->
</body>
</html>